#include "C_ListItem.h"
#include "C_List.h"

using namespace gui;

C_ListItem::C_ListItem()
{
	this->setContainerType(CONTAINER_VERTICAL);
	this->setHorizontalAlign(GRID_CENTER);
	this->setVerticalAlign(GRID_MIDDLE);
	this->addWidget(&m_label);
	this->setBackgroundVisible(true);
	this->setBackgroudColor(RGB2ONE(16), RGB2ONE(16), RGB2ONE(16));

	this->setTextSize(16);
	this->setSize(200, 20);
	m_list = nullptr;
}

C_ListItem::C_ListItem(std::wstring t, void* data)
{
	m_data = data; m_label.setText(t);

	this->setContainerType(CONTAINER_VERTICAL);
	this->setHorizontalAlign(GRID_CENTER);
	this->setVerticalAlign(GRID_MIDDLE);
	this->addWidget(&m_label);
	this->setBackgroundVisible(true);
	this->setBackgroudColor(RGB2ONE(16), RGB2ONE(16), RGB2ONE(16));

	this->setTextSize(16);
	this->setSize(200, 20);
	m_list = nullptr;
}

void C_ListItem::setList(C_List* list)
{
	m_list = list;
}


C_ListItem::~C_ListItem()
{
}

void C_ListItem::renderWidget()
{
	if (this->isMouseButtonPress() && this->mouseButton() == sf::Mouse::Button::Left)
	{
		m_list->setSelectItem(this);
	}

	if (this->m_selected)
	{
		this->setBackgroudColor(RGB2ONE(220), RGB2ONE(0), RGB2ONE(220));
		m_label.setColorText(sf::Color(0, 0, 0));
	}

	if (this->isMouseOver())
	{
		this->setBackgroudColor(RGB2ONE(0), RGB2ONE(230), RGB2ONE(230));
		m_label.setColorText(sf::Color(0, 0, 0));
	}
	else if (this->m_selected != true)
	{
		this->setBackgroudColor(RGB2ONE(16), RGB2ONE(16), RGB2ONE(16));
		m_label.setColorText(sf::Color(255, 255, 255));
	}
}

void C_ListItem::syncWidgets()
{

}
